package cn.fay.chapter15;

public class BasicGenerator<T> implements Generator<T> {
	private Class<T> type;
	public BasicGenerator(Class<T> type) {
		this.type=type;
	}
	public static <T> BasicGenerator<T> create(Class<T> type) {
		return new BasicGenerator<T>(type);
	}
	@Override
	public T next() {
		try {
	 		return type.newInstance();
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage());
		}
	}
	public static void main(String[] args) {
		 BasicGenerator<Fibonacci> bg = BasicGenerator.create(Fibonacci.class);
		 Fibonacci fibonacci = bg.next();
		 for(int i=0;i<18;i++){
			 System.out.print(fibonacci.next()+", ");
		 }
	}
}
